package com.ruoyi.extend.service.impl;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.db.mapper.ChannelUnionInfoMapper;
import com.ruoyi.db.domain.ChannelUnionInfo;
import com.ruoyi.extend.service.IChannelUnionInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 联登渠道信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-19
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class ChannelUnionInfoServiceImpl implements IChannelUnionInfoService 
{
    @Autowired
    private ChannelUnionInfoMapper ChannelUnionInfoMapper;

    /**
     * 查询联登渠道信息
     * 
     * @param id 联登渠道信息主键
     * @return 联登渠道信息
     */
    @Override
    public ChannelUnionInfo selectChannelUnionInfoById(String id)
    {
        return ChannelUnionInfoMapper.selectChannelUnionInfoById(id);
    }

    /**
     * 查询联登渠道信息列表
     * 
     * @param ChannelUnionInfo 联登渠道信息
     * @return 联登渠道信息
     */
    @Override
    public List<ChannelUnionInfo> selectChannelUnionInfoList(ChannelUnionInfo ChannelUnionInfo)
    {
        return ChannelUnionInfoMapper.selectChannelUnionInfoList(ChannelUnionInfo);
    }

    /**
     * 查询联登渠道信息列表
     *
     * @param ChannelUnionInfo 联登渠道信息
     * @return 联登渠道信息
     */
    @Override
    public List<Map<String, Object>> selectChannelUnionInfoListMap(ChannelUnionInfo ChannelUnionInfo)
    {
        return ChannelUnionInfoMapper.selectChannelUnionInfoListMap(ChannelUnionInfo);
    }

    /**
     * 新增联登渠道信息
     * 
     * @param ChannelUnionInfo 联登渠道信息
     * @return 结果
     */
    @Override
    public int insertChannelUnionInfo(ChannelUnionInfo ChannelUnionInfo)
    {
        ChannelUnionInfo.setCreateTime(DateUtils.getNowDate());
        return ChannelUnionInfoMapper.insertChannelUnionInfo(ChannelUnionInfo);
    }

    /**
     * 修改联登渠道信息
     * 
     * @param channelUnionInfo 联登渠道信息
     * @return 结果
     */
    @Override
    public int updateChannelUnionInfo(ChannelUnionInfo channelUnionInfo)
    {

        if (StringUtils.isNotEmpty(channelUnionInfo.getUnionProdIds())){
            String[] split = channelUnionInfo.getUnionProdIds().split(",");
            JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(split));
            channelUnionInfo.setUnionProdIds(jsonArray.toJSONString());
        }else{
            channelUnionInfo.setUnionProdIds(new JSONArray().toJSONString());
        }

        channelUnionInfo.setUpdateTime(DateUtils.getNowDate());
        return ChannelUnionInfoMapper.updateChannelUnionInfo(channelUnionInfo);
    }

    /**
     * 批量删除联登渠道信息
     * 
     * @param ids 需要删除的联登渠道信息主键
     * @return 结果
     */
    @Override
    public int deleteChannelUnionInfoByIds(String ids)
    {
        return ChannelUnionInfoMapper.deleteChannelUnionInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除联登渠道信息信息
     * 
     * @param id 联登渠道信息主键
     * @return 结果
     */
    @Override
    public int deleteChannelUnionInfoById(String id)
    {
        return ChannelUnionInfoMapper.deleteChannelUnionInfoById(id);
    }
}
